<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>蚂蚁</title>
  </head>
  <body></body>
  <script>
    let frameFun = null
    window.onload = function () {
      console.log('Loading...')
      let x = 0
      //   let y = 0
      const body = document.getElementsByTagName('body')[0]
      const fragment = document.createDocumentFragment()
      let y = 0
      while (y < 1080) {
        const divDom = document.createElement('div')
        divDom.style.backgroundColor = 'red'
        fragment.appendChild(divDom)
        y++
      }
      const renderDiv = () => {
        x += 1
        if (x <= (1920 * 1080) / 2 / 2) {
          body.appendChild(fragment)
          frameFun = requestAnimationFrame(renderDiv)
        } else {
          cancelAnimationFrame(frameFun)
        }
      }
      let z = 0
      renderDiv()
      /* while (z < 100) {
        console.log('z', z)
        renderDiv()
        z++
      } */
    }
    window.onunload = function () {
      cancelAnimationFrame(frameFun)
      console.log('onunload')
    }
  </script>
  <style>
    * {
      padding: 0;
      margin: 0;
      box-sizing: border-box;
    }
    body {
      display: flex;
      flex-wrap: wrap;
      /* justify-items: flex-start; */
      align-content: flex-start;
      width: 1920px;
      height: 1080px;
    }
    div {
      /* width: 2px; */
      width: 2px;
      height: 2px;
    }
  </style>
</html>
